// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const set = (key: string, value: any) => {
  if (window.electron) {
    window.electron.ipcRenderer.setStoreValue(key, value)
  } else {
    localStorage.setItem(key, value)
  }
}

export const get = (key: string) => {
  let data
  if (window.electron) {
    data = window.electron.ipcRenderer.getStoreValue(key)
  } else {
    data = localStorage.getItem(key)
  }

  return data
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const setJson = (key: string, value: any) => {
  if (window.electron) {
    window.electron.ipcRenderer.setStoreValue(key, JSON.stringify(value))
  } else {
    localStorage.setItem(key, JSON.stringify(value))
  }
}

export const getJson = (key: string) => {
  let data
  if (window.electron) {
    data = window.electron.ipcRenderer.getStoreValue(key)
  } else {
    data = localStorage.getItem(key)
  }

  if (data) {
    return JSON.parse(data)
  }
  return data
}

export const remove = (key: string) => {
  if (window.electron) {
    window.electron.ipcRenderer.removeStoreValue(key)
  } else {
    localStorage.removeItem(key)
  }
}

export const clear = () => {
  if (window.electron) {
    window.electron.ipcRenderer.clearStoreValue()
  } else {
    localStorage.clear()
  }
}
